<!DOCTYPE html>
<html>

	<head lang="en">
		<title>找攻略</title>
		<meta charset="utf-8" />
		<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
		<link rel="stylesheet" href="/js/bootstrap/css/bootstrap.min.css">
		<script src="/js/jquery/jquery.min.js"></script>
		<script src="/js/bootstrap/js/bootstrap.min.js"></script>
		<link rel="stylesheet" href="/css/font/css/font-awesome.min.css" />
		<link rel="stylesheet" href="/css/reset.css" />
		<link rel="stylesheet" href="/css/strategy.css" />
		<link rel="stylesheet" href="/js/plugins/dialog2/dialog.css" />
		<script src="/js/plugins/jrender/jrender.min.js"></script>
		<script src="/js/plugins/dialog2/dialog.min.js"></script>
		<link rel="stylesheet" href="/js/plugins/chosen/component-chosen.css">
		<script src="/js/plugins/chosen/chosen.jquery.js"></script>
		<script>
			$(function () {



                //分页查询需要拼接的临时变量
                var currentPage = 2;
                //总页数变量
                var totalPage = 2;
				//将所有的推荐地区查询出来
                var regionId;
				$.get("regions/1",function (data) {
                    //拼接在标签页上面
                    var html= "";
                    var content="";
                    $.each(data,function (index, item) {
                        html+='<li class="nav-item"><a data-id="'+item.id+'" class="nav-link" id="pills-'+item.id+'-tab" data-toggle="pill" href="#pills-'+item.id+'">'+item.name+'</a></li>'
						//根据地区显示内容的 div头
						content += '<div class="tab-pane fade" id="pills-'+item.id+'"></div>';
                        //拼接导导航栏的内容(推荐)
                        $('#pills-tabContent').append(content);
                    })
                    //拼接导航栏的标题(推荐地区)
                    $('#pills-tab').append(html);

                    //给地区绑定一个点击事件
                    $(".nav-link").click(function () {
                        //地区的id
						//每次点击事件都把currentpage初始化,推荐地区
                        currentPage = 2;
                        regionId = $(this).data('id');
                        if (regionId){ //如果是推荐界面呢也会发送ajax,排除
                            //data-html 格式的   //此时的返回值就是一个模板加数据返回的结果
                            $.get("/regions/"+regionId+"/strategies",function (data) {
                                $('#pills-'+regionId).html(data);
                            },"html")
                        }
                    })
                });
/*
                //分页查询需要拼接的临时变量
                var currentPage = 2;
                //解决上一1页时数据丢失的问题
                var dataList = [];
                //总页数变量
                var totalPage = 2;
                //方法的抽取*/
                function query() {
                    if (regionId){
                    $.get("/regions/"+regionId+"/strategies",{currentPage:currentPage,pageSize:8} ,function (data) {
                        //在第一页全部攻略后面拼接处第二页数据
                        console.log(data);
                        var html = "";
						$.each(data.list,function (index,item) {
                            html+= '<div class="col-6 mb">' +
                                '                <a href="../strategyCatalogs.html?strategyId='+item.id+'">' +
                                '                    <img class="float-left " src="'+item.coverUrl+'">' +
                                '                    <div class="classify-text">' +
                                '                        <span>'+item.subTitle+'</span>' +
                                '                        <p>'+item.count+'人收藏</p>'+
                                '                    </div>' +
                                '                </a>' +
                                '            </div>';
                        })
						//将全部攻略添加到里面
						$('.classify').append(html);
                        totalPage = data.pages;
                    },"json")
                }
                }
                /*//第一次查询 不需要第一次查询
                query();*/
                $(window).scroll(function () {
                    if ($(window).height()+$(document).scrollTop()+1>=$(document).height()) {
                        console.log(currentPage +""+ totalPage);
                        if (currentPage<=totalPage) {
                            query();
                            currentPage += 1;
                        } else {
                            $(document).dialog({
                                type: "notice",
                                infoText: "到底了........",
                                autoClose: 1000,
                                position: "bottom" //在底部显示
                            })
                        }
                    }
                })
				//----------------------------------------------------------
				//查询功能

				$.get('strategys', {pageSize:0}, function (data) {



                    $('#strategies').append("<option value='-1'>-寻找攻略-</option>")

                    var op = "";
					$.each(data, function (index, item) {
						op+= "<option value='"+item.id+"'>"+item.title+"</option>"
                    })



                    $("#strategies").append(op);
					$("#strategies").chosen({
						no_results_text: "无相关地区!",//搜索无结果时显示的提示
						disable_search_threshold: 5,//选项小于5时不显示搜索框
						search_contains:true,   //关键字模糊搜索，设置为false，则只从开头开始匹配
						allow_single_deselect:true, //是否允许取消选择
						max_selected_options:6  //当select为多选时，最多选择个数
					})
					$('.chosen-select').on('change', function(e, params) {
						console.log(params);
						window.location.href="/strategyCatalogs.html?strategyId="+params.selected
					});
				})


                //查询所有的推荐攻略
                $.get('strategys',{state:1,pageSize:0},function (data) {
                    $(".strategyCommend").renderValues({list:data},{
                        setHref:function (item, value) {
                            $(item).attr("href",$(item).data("href")+value)
                        }
                    });
                })
                //查询所有攻略推荐的文章
                $.get('travels/commends',{type:2},function (data) {
                    $(".commend").renderValues(data.list[0],{
                        setHref:function (item, value) {
                            $(item).attr("href",$(item).data("href")+value)
                        }
                    });
                })




            })
		</script>
	</head>
	<body>
	<div class="search-head">
		<div class="row nav-search">
			<div class="col-2">
				<a href="index.html">
					<span><i class="fa fa-chevron-left fa-2x"></i></span>
				</a>
			</div>
			<div class="col-10">
				<div class="input-group-sm search" >
					<select id="strategies" class="chosen-select form-control" name="strategy.id"
					render-value="strategy.id" >
					<span style="position: absolute; top: 10px; left: 140px; color: black;font-size: 20px" class="nameBtn">搜索旅行攻略</span>
					</select>
				</div>
			</div>
		</div>
	</div>

	<ul class="nav nav-pills nav-justified border border-left-0 border-top-0 border-right-0" id="pills-tab" role="tablist">
		<li class="nav-item">
			<a class="nav-link active show" id="pills-top-tab" data-toggle="pill" href="#pills-top">
				<span style="font-weight: bold;">推荐</span>
			</a>
		</li>
	</ul>

	<div class="tab-content" id="pills-tabContent">
		<div class="tab-pane fade active show" id="pills-top">
			<div class="container commend">
				<a data-href="travelContent.html?id=" render-fun="setHref" render-key="travel_id">
					<img  render-src="coverUrl">
					<p render-html="title"></p>
				</a>
			</div>
			<hr>
			<div class="container strategyCommend">
				<h6>当季推荐</h6>
				<div class="row hot" render-loop="list">
					<div class="col-4" >
					<a data-href="strategyCatalogs.html?strategyId=" render-fun="setHref" render-key="list.id">
						<img  render-src="list.coverUrl">
						<p render-html="list.title"></p>
					</a>
				    </div>
				</div>
			</div>
		</div>
	</div>
	</body>

</html>